#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
string s;
int a[N];
int ans[N][3][3];
int n;
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf_s("%d", &a[i]);
	}
	cin >> s;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			ans[i][1][j] = ans[i - 1][1][j];
		}
		if (s[i] == 'M') {
			ans[i][1][a[i]]++;
		}
	}
	for (int i = n - 1; i >= 0; i--) {
		for (int j = 0; j < 3; j++) {
			ans[i][3][j] = ans[i + 1][3][j];
		}
		if (s[i] == 'X') {
			ans[i][3][a[i]]++;
		}
	}
	//for (int i = 0; i < n; i++) {
	//	cout << "i==" << i << endl;
	//	for (int j = 0; j <= 2; j++) {
	//		cout << "ans[i][1][j]==" << " j==" << ans[i][1][j] << endl;
	//		//cout << "ans[i][3][j]==" << " j==" << ans[i][3][j] << endl;
	//	}
	//}
	LL res = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'E') {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					LL x = ans[i - 1][1][j];
					LL y = ans[i + 1][3][k];
					int temp = 0;
					bool flag = 0;
					for (int z = 0; z <= 2; z++) {
						if (j == z || k == z || a[i] == z)continue;
						else {
							temp = z;
							flag = 1;
							break;
						}
					}
					//cout << "flag==" << flag << endl;
					//cout << "x==" << x << endl;
					//cout << "y==" << y << endl;
					//cout << "temp==" << temp << endl;
					if (!flag) {
						res += (x * y) * 3;
					}
					else res += (x * y) * temp;
					//cout << "res==" << res << endl;
				}
			}
		}
	}
	cout << res << endl;
	return 0;
}